package cn.zyjblogs.starter.common.exception;

import cn.zyjblogs.starter.common.entity.response.HttpCode;
import cn.zyjblogs.starter.common.utils.string.StringUtils;

/**
 * @author zhuyijun
 */
public class AbstractBusinessException extends RuntimeException {
    private static final long serialVersionUID = -6583471361241853199L;
    /**
     * 异常码
     */
    private HttpCode responseCode;

    /**
     * 异常描述
     */
    private String message;


    public AbstractBusinessException() {

    }

    /**
     * 创建业务异常对象
     *
     * @param responseCode 错误码
     * @param message      错误消息
     */
    public AbstractBusinessException(HttpCode responseCode, String message) {
        super(message);
        this.responseCode = responseCode;
        this.message = message;
    }

    /**
     * 创建业务异常对象
     *
     * @param message 错误消息
     */
    public AbstractBusinessException(String message) {
        super(message);
        this.responseCode = HttpCode.INTERNAL_SERVER_ERROR;
        this.message = message;
    }

    /**
     * 创建业务异常对象
     *
     * @param message 错误消息
     */
    public AbstractBusinessException(String message, Object... params) {
        super(StringUtils.format(message, params));
        this.responseCode = HttpCode.INTERNAL_SERVER_ERROR;
        this.message = message;
    }

    /**
     * 创建业务异常对象
     *
     * @param responseCode 错误码
     * @param message      错误消息
     */
    public AbstractBusinessException(HttpCode responseCode, String message, Object... params) {
        super(StringUtils.format(message, params));
        this.responseCode = responseCode;
        this.message = message;
    }
}
